package com.shujia.wyh.mrdemos;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/*
    统计文本中曹操，董卓，刘备三个词语出现的次数
 */
public class SgyyCountDemo {
    public static void main(String[] args) throws Exception {
        //获取hadoop的配置文件
        Configuration conf = new Configuration();

        //创建作业
        Job job = Job.getInstance(conf);

        //给job作业设置作业的名字
        job.setJobName("统计文本中曹操，董卓，刘备三个词语出现的次数");

        //设置job运行的主类
        job.setJarByClass(SgyyCountDemo.class);

        //设置map类
        job.setMapperClass(MyMapper2.class);
        //设置map类的输出key和value类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        //设置reduce类
        job.setReducerClass(MyReducer2.class);
        //设置reduce类的输出key和value类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        //设置文件输入路径
        FileInputFormat.addInputPath(job,new Path(args[0]));
        //设置结果的输出路径
        FileOutputFormat.setOutputPath(job,new Path(args[1]));


        //启动作业，开始执行
        job.waitForCompletion(true);

    }
}
